/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Cookie script - Scott Andrew
Popup script, Copyright 2005, Sandeep Gangadharan */

function newCookie(name,value,days){
        var days = 10;   // the number at the left reflects the number of days for the cookie to last
        if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString(); 
        }
        else{
                var expires = "";
        }
        document.cookie = name+"="+value+expires+"; path=/"; 
}

function readCookie(name) {
        var nameSG = name + "=";
        var nuller = '';
        if (document.cookie.indexOf(nameSG) == -1){
                return nuller;
        }        
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++) {
                var c = ca[i];
                while (c.charAt(0)==' '){
                        c = c.substring(1,c.length);
                }
                if (c.indexOf(nameSG) == 0){
                        return c.substring(nameSG.length,c.length); 
                }
        }
        return nuller; 
}

function eraseCookie(name) {
        newCookie(name,"",1); 
}

function setCookie(obj){
        var user_name = document.getElementById('user_name');
        var user_pwd = document.getElementById('user_password');
        if(obj.checked){
                if(user_name.value!=''&&user_pwd.value!=''){
                        newCookie('user_name',user_name.value);
                        newCookie('user_pwd',user_pwd.value);
                }
        }
        else{
                if(readCookie('user_name')!=''){
                        eraseCookie('user_name');
                        eraseCookie('user_pwd');
                }
        }
        return true;
}

function getCookie(){
		var user_name = document.getElementById('user_name');
		var user_pwd = document.getElementById('user_password');
		if(QueryString('flag')=='1'){
				eraseCookie('user_name');
				eraseCookie('user_pwd');
		}
		user_name=readCookie('user_name');
		user_pwd=readCookie('user_pwd');
		document.getElementById('user_name').value=user_name;
		document.getElementById('user_password').value=user_pwd;
		login_form=document.getElementById('login_form');		
		if(user_name!='' && user_pwd!=''){
				login_form.submit();
		}
}
function QueryString(sName){  
		var sSource = String(window.document.location);  
		var sReturn = "";  
		var sQUS = "?";  
		var sAMP = "&";  
		var sEQ = "=";  
		var iPos;  
		
		iPos = sSource.indexOf(sQUS);
		var strQuery = sSource.substr(iPos,sSource.length - iPos);  
		var strLCQuery = strQuery.toLowerCase();  
		var strLCName = sName.toLowerCase();  
		
		iPos = strLCQuery.indexOf(sQUS + strLCName + sEQ);  
		if (iPos == -1){  
				iPos = strLCQuery.indexOf(sAMP + strLCName + sEQ);  
				if(iPos == -1)  
						return "";  
		}
		sReturn = strQuery.substr(iPos + sName.length + 2,strQuery.length-(iPos + sName.length + 2));  
		var iPosAMP = sReturn.indexOf(sAMP);  
		
		if (iPosAMP == -1)  
				return sReturn;  
		else{  
				sReturn = sReturn.substr(0, iPosAMP);  
		}
		return sReturn;  
}   
